﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Instrument;

namespace UI
{
    public partial class ProductionChoice : DevExpress.XtraEditors.XtraForm
    {
        IEnumerable<Production> ProductionList;
        Production CurrentProduction;
        public delegate void TransInfo(Production s);
        public event TransInfo TransInfoEvent;
        public ProductionChoice()
        {
            InitializeComponent();
            ProductionList = DataBaseOperation.GetInstance().GetAllProduction();
            foreach(var item in ProductionList)
            {
                radioGroup1.Properties.Items.Add(new DevExpress.XtraEditors.Controls.RadioGroupItem(item,item.Model));
            }
        }

        private void radioGroup1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Production production = (Production)radioGroup1.Properties.Items[radioGroup1.SelectedIndex].Value;
            txtEditModel.Text = production.Model;
            txtEditChannel.Text = production.ResistanceCount.ToString();
            txtEditOffset.Text = production.AllowOffset.ToString();
            txtEditQulified.Text = production.QualifiedResistance.ToString();
            txtEditRange.Text = production.Range.ToString();
            CurrentProduction = production;
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            if(CurrentProduction == null)
            {
                MessageBox.Show("请选择一种产品");
                return;
            }
            TransInfoEvent?.Invoke(CurrentProduction);
            this.Close();
        }
    }
}